Skip to content

Conversation

@OdenTakashi
Copy link
Contributor

@OdenTakashi OdenTakashi commented Sep 24, 2025

Problem

In a multi-database environment, it can be confusing to determine which database a model's table belongs to just by looking at the schema annotations. This can lead to developers mistakenly thinking a table is missing when it simply resides in a different database.

Solution

This commit introduces a new line in the schema information block that conditionally displays the database name.

  • In multi-database environments, the database name is now shown to provide clarity:
# == Schema Information
#
# Table name: tasks
# Database name: second_database
#
# ...
  • In single-database environments, the database name is not displayed to avoid unnecessary clutter.

Refs #254

I really enjoy contributing to this gem and hope to contribute even more.
Thank you for always maintaining it! 👍

## Problem

In a multi-database environment, it can be confusing to determine which
database a model's table belongs to just by looking at the schema
annotations. This can lead to developers mistakenly thinking a table
is missing when it simply resides in a different database.

## Solution

This commit introduces a new line in the schema information block that
conditionally displays the database name.

- In multi-database environments, the database name is now shown to
provide clarity:

# == Schema Information
#
# Table name: tasks
# Database name: second_database
#
# ...

- In single-database environments, the database name is not displayed
to avoid unnecessary clutter.

Refs drwl#254
Copy link
Owner

@drwl drwl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Seems like the ActiveRecord APIs were added in Rails 6 so we should be good:

https://www.bigbinary.com/blog/rails-6-changed-activerecord-base-configurations-result-to-an-object

@drwl drwl merged commit 57f7901 into drwl:main Oct 20, 2025
22 checks passed
@OdenTakashi
Copy link
Contributor Author

Thank you for taking the time to review this despite your busy schedule !

@OdenTakashi OdenTakashi deleted the feature/add-db-name-annotation-on-multi-db branch October 20, 2025 13:45
t27duck added a commit to t27duck/annotaterb that referenced this pull request Oct 21, 2025
New "modern" Rails apps default to using the "solid trifecta" of solidqueue, cache, and cable. The generator defaults to creating a separate database for each feature meaning all new Rails apps would be multi-database out of the box.

With the introduction of drwl#272 all Rails apps with the trifecta configured will have "Database: primary" appended to every annotated file even though there's really one database the developer cares about as the other gems provide their own models and handling.

This adds an "ignore_multi_database_name" configuration option which disables including the database name even if the app has multiple databases.
drwl pushed a commit that referenced this pull request Oct 22, 2025
New "modern" Rails apps default to using the "solid trifecta" of
solidqueue, cache, and cable. The generator defaults to creating a
separate database for each feature meaning all new Rails apps would be
multi-database out of the box.

With the introduction of #272
all Rails apps with the trifecta configured will have "Database:
primary" appended to every annotated file even though there's really one
database the developer "cares" about as the other gems provide their own
models and handling.

This adds an "ignore_multi_database_name" configuration option which
disables including the database name even if the app has multiple
databases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants